package com.excuse.excusebuilder.presenter;

import android.content.Context;

import com.excuse.excusebuilder.bean.Post;
import com.excuse.excusebuilder.bean.User;
import com.excuse.excusebuilder.commen.util.ToastUtil;
import com.excuse.excusebuilder.impl.view.AddPostFragmentInterface;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

/**
 * Created by U-nookia on 2017/4/19.
 */

public class AddPostPresenter {
    private Context context;
    private AddPostFragmentInterface addPostFragment;

    public AddPostPresenter(Context context, AddPostFragmentInterface addPostFragment) {
        this.context = context;
        this.addPostFragment = addPostFragment;
    }

    public void savePostToBmob(String title,String content) {
        Post post = new Post();
        post.setUser(BmobUser.getCurrentUser(User.class));
        post.setTitle(title);
        post.setContent(content);
        post.setLikeNum(0);
        post.save(new SaveListener<String>() {
            @Override
            public void done(String s, BmobException e) {
                if (e!=null) {
                    ToastUtil.makeShortToast(context,e.toString());
                    return;
                }
                ToastUtil.makeShortToast(context,"发布成功");
                addPostFragment.finishView();
            }
        });
    }
}
